home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / Apple Game Sprockets / Examples / SoundSprocketTest / TS3Message.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-16  |  3.4 KB  |  170 lines  |  [TEXT/CWIE]

  1. /*
  2.  *    File:        TS3Message.c
  3.  *    Author:        Dan Venolia
  4.  *
  5.  *    Copyright © 1996 Apple Computer, Inc.
  6.  */
  7.  
  8. #include <assert.h>
  9. #include <string.h>
  10.  
  11. #include <Dialogs.h>
  12. #include <SegLoad.h>
  13.  
  14. #include "SoundSprocket.h"
  15.  
  16. #include "TS3Message.h"
  17. #include "TS3Resource.h"
  18.  
  19.  
  20. typedef struct TMessageIgnore {
  21.     struct TMessageIgnore*    next;
  22.     
  23.     OSStatus                err;
  24.     unsigned long            line;
  25.     
  26.     char                    func[64];
  27. } TMessageIgnore;
  28.  
  29.  
  30. typedef struct TMessageError {
  31.     OSStatus                err;
  32.     char*                    msg;
  33. } TMessageError;
  34.  
  35.  
  36. static TMessageIgnore*        gMessageIgnore = NULL;
  37.  
  38. static TMessageError        gMessageError[] = {
  39.     {kSSpInternalErr,            "kSSpInternalErr"},
  40.     {kSSpVersionErr,            "kSSpVersionErr"},
  41.     {kSSpCantInstallErr,        "kSSpCantInstallErr"},
  42.     {kSSpParallelUpVectorErr,    "kSSpParallelUpVectorErr"},
  43.     {kSSpScaleToZeroErr,        "kSSpScaleToZeroErr"},
  44.     {0,                            NULL}
  45. };
  46.  
  47.  
  48. /* =============================================================================
  49.  *        Message_Init (external)
  50.  *
  51.  *    Initializes our message thing.
  52.  * ========================================================================== */
  53. void Message_Init(
  54.     void)
  55. {
  56. }
  57.  
  58.  
  59. /* =============================================================================
  60.  *        Message_Exit (external)
  61.  *
  62.  *    Cleans up.
  63.  * ========================================================================== */
  64. void Message_Exit(
  65.     void)
  66. {
  67.     //• TODO: Dispose the "ignore" list
  68. }
  69.  
  70.  
  71. /* =============================================================================
  72.  *        _Message_CheckError (external)
  73.  *
  74.  *    If inErr is not noErr, then an alert is posted with Continue and Quit
  75.  *    buttons.
  76.  * ========================================================================== */
  77. void _Message_CheckError(
  78.     OSStatus            inErr,
  79.     const char*            inInRoutine,
  80.     const char*            inFromRoutine,
  81.     const char*            inFile,
  82.     unsigned long        inLine)
  83. {
  84.     TMessageIgnore*        ignore;
  85.     TMessageError*        messageError;
  86.     char                errorText[64];
  87.     Str255                message;
  88.     
  89.     if (inErr == noErr)  return;
  90.     
  91.     // Check our "ignore" list
  92.     ignore = gMessageIgnore;
  93.     while (ignore != NULL)
  94.     {
  95.         if (ignore->err        == inErr        &&
  96.             ignore->line    == inLine        &&
  97.             strcmp(ignore->func, inInRoutine) == 0)
  98.         {
  99.             return;
  100.         }
  101.         else
  102.         {
  103.             ignore = ignore->next;
  104.         }
  105.     }
  106.     
  107.     // See if we know the name of the beast from the number of the beast
  108.     messageError = gMessageError;
  109.     while (messageError->err != 0 &&
  110.            messageError->err != inErr)
  111.     {
  112.         messageError += 1;
  113.     }
  114.     
  115.     // Make a string from the error message
  116.     if (messageError->msg != NULL)
  117.     {
  118.         sprintf(errorText, "%s (%ld)", messageError->msg, inErr);
  119.     }
  120.     else
  121.     {
  122.         sprintf(errorText, "%ld", inErr);
  123.     }
  124.     
  125.     // Format the message
  126.     sprintf((char*) message, "xError %s returned by %s.  Called from %s at line %ld of “%s”.",
  127.             errorText,
  128.             inFromRoutine,
  129.             inInRoutine,
  130.             inLine,
  131.             inFile);
  132.     
  133.     message[0] = strlen((char*) message) - 1;
  134.     
  135.     // Put up the alert and handle the results
  136.     ParamText(message, NULL, NULL, NULL);
  137.     
  138.     switch (StopAlert(kAlrtID_Error, NULL))
  139.     {
  140.         case kErrorItem_Continue:
  141.             // do nothing
  142.         break;
  143.         
  144.         case kErrorItem_Ignore:
  145.             // Add to our list of errors to ignore
  146.             ignore = (TMessageIgnore*) NewPtr(sizeof(TMessageIgnore));
  147.             assert(ignore != NULL);
  148.             
  149.             ignore->next = gMessageIgnore;
  150.             gMessageIgnore = ignore;
  151.             
  152.             ignore->err = inErr;
  153.             ignore->line = inLine;
  154.             
  155.             assert(strlen(inInRoutine) < 64);
  156.             strcpy(ignore->func, inInRoutine);
  157.         break;
  158.         
  159.         case kErrorItem_Quit:
  160.             // Goodbye
  161.             ExitToShell();
  162.         break;
  163.         
  164.         default:
  165.             assert(0);
  166.     }
  167. }
  168.  
  169.  
  170.